package com.pf.java;

import java.sql.SQLOutput;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 双端队列
 *
 * @author pf
 * @data 2021/11/1-10:11
 */
public class deque {

    public static void main(String[] args) {
        Deque deque = new ArrayDeque();
        deque.offer("Mary");
        deque.offer("Lily");
        deque.offer("Tony");
        System.out.println(deque);

        deque.offerFirst("John");
        System.out.println(deque);

        deque.offerLast("Lucy");
        System.out.println(deque);

        System.out.println(deque.peekFirst()); // == peek()
        System.out.println(deque.peekLast());
        System.out.println(deque);

        while (deque.size() > 0) {
            System.out.println(deque.pollLast());
//            System.out.println(deque.pollFirst()); //== poll()
        }
        System.out.println(deque);


        // 栈操作

        Deque stack = new ArrayDeque();
        stack.push("唐僧");
        stack.push("悟空");
        stack.push("八戒");
        System.out.println(stack);

        while (stack.size() > 0) {
            System.out.println(stack.pop());
        }
        System.out.println(stack);

    }
}
